package com.rmxx.fruit.activity;

import android.graphics.Color;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.company.android.fruit.R;
import com.kwan.xframe.common.widget.observablescrollview.ObservableRecyclerView;
import com.kwan.xframe.mvp.presenter.BasePresenter;
import com.kwan.xframe.mvp.view.activity.BaseCommonActivity;
import com.rmxx.fruit.bean.Product;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class OrderListActivity extends BaseCommonActivity {
	protected ObservableRecyclerView mRecyclerView;
	protected BaseQuickAdapter mAdapter;
	protected int pageIndex = 0;
	protected int pageSize = 10;
	protected boolean isLoadMore;
	protected boolean hasMoreData = true;

	public boolean isRefreshing;
	List<Product> mProduct = new ArrayList<>();

	private View v_line_all, line_by_pay, line_by_send, line_by_get, line_by_comment, ll_all, ll_by_pay, ll_by_send, ll_by_get, ll_by_comment;
	private TextView tv_all, tv_by_pay, tv_by_send, tv_by_get, tv_by_comment;

	@Override
	protected BasePresenter getBasePresenter() {
		return null;
	}

	@Override
	protected void initViews() {
		super.initViews();

		v_line_all = findViewById(R.id.v_line_all);
		line_by_pay = findViewById(R.id.line_by_pay);
		line_by_send = findViewById(R.id.line_by_send);
		line_by_get = findViewById(R.id.line_by_get);
		line_by_comment = findViewById(R.id.line_by_comment);

		ll_all = findViewById(R.id.ll_all);
		ll_by_pay = findViewById(R.id.ll_by_pay);
		ll_by_send = findViewById(R.id.ll_by_send);
		ll_by_get = findViewById(R.id.ll_by_get);
		ll_by_comment = findViewById(R.id.ll_by_comment);

		tv_all = findViewById(R.id.tv_all);
		tv_by_pay = findViewById(R.id.tv_by_pay);
		tv_by_send = findViewById(R.id.tv_by_send);
		tv_by_get = findViewById(R.id.tv_by_get);
		tv_by_comment = findViewById(R.id.tv_by_comment);


		Product product = new Product();
		product.setRicon(R.mipmap.product4_01);
		product.setName("【2袋】张君雅拉面丸子100g");
		product.setDesc("我的火辣不要轻易挑战哦");
		product.setPrice(6.66f);
		mProduct.add(product);

		product = new Product();
		product.setRicon(R.mipmap.product4_02);
		product.setName("真丽斯沐浴露持久留香");
		product.setDesc("洗澡就能护肤");
		product.setPrice(48.00f);
		mProduct.add(product);

		product = new Product();
		product.setRicon(R.mipmap.product4_03);
		product.setName("瑞松秋刀鱼即食海鲜类鱼干");
		product.setDesc("嚼劲十足 鲜香炭烤 深海捕捞");
		product.setPrice(48.00f);
		mProduct.add(product);

		mAdapter =
				new BaseQuickAdapter<Product, BaseViewHolder>(R.layout.list_item_order, mProduct) {
					@Override
					protected void convert(BaseViewHolder helper, Product item) {
//						helper.setImageResource(R.id.iv_icon, item.getRicon());
//						helper.setText(R.id.tv_name, item.getName());
//						helper.setText(R.id.tv_price, "¥" + item.getPrice());
//						helper.setText(R.id.tv_desc, item.getDesc());
					}
				};
		mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
			@Override
			public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
				//go2Activity(ProductActivity.class,null,false);
			}
		});

		mRecyclerView = findViewById(R.id.recycleView);
		mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
		mRecyclerView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
		mRecyclerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
		mRecyclerView.setHasFixedSize(true);

		//mRecyclerView.setItemAnimator(new DefaultItemAnimator());
		//解决更新 闪烁
		mRecyclerView.setItemAnimator(null);
		mRecyclerView.setNestedScrollingEnabled(false);
		mAdapter.bindToRecyclerView(mRecyclerView);
		mAdapter.setEmptyView(R.layout.layout_no_order);
		mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
			@Override
			public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
				go2Activity(OrderActivity.class,null,false);
			}
		});
	}

	@Override
	protected void initViewSetting() {
		super.initViewSetting();

		ll_all.setOnClickListener(this);
		ll_by_pay.setOnClickListener(this);
		ll_by_send.setOnClickListener(this);
		ll_by_get.setOnClickListener(this);
		ll_by_comment.setOnClickListener(this);
	}

	@Override
	protected void initData() {

	}

	@Override
	protected String getTitleTxt() {
		return null;
	}

	@Override
	public String getPageName() {
		return null;
	}

	@Override
	protected int getTopViewId() {
		return 0;
	}

	@Override
	protected int getMainViewId() {
		return R.layout.activity_order_list;
	}

	@Override
	protected int getBottomViewId() {
		return 0;
	}

	@Override
	public void onClick(View v) {
		super.onClick(v);

		if (v == ll_all) {

			tv_all.setTextColor(getResources().getColor(R.color.mainRed));
			tv_by_pay.setTextColor(Color.parseColor("#999999"));
			tv_by_send.setTextColor(Color.parseColor("#999999"));
			tv_by_get.setTextColor(Color.parseColor("#999999"));
			tv_by_comment.setTextColor(Color.parseColor("#999999"));

			v_line_all.setVisibility(View.VISIBLE);
			line_by_pay.setVisibility(View.INVISIBLE);
			line_by_send.setVisibility(View.INVISIBLE);
			line_by_get.setVisibility(View.INVISIBLE);
			line_by_comment.setVisibility(View.INVISIBLE);

			Collections.shuffle(mProduct);
			mAdapter.setNewData(mProduct);

		} else if (v == ll_by_pay) {

			tv_by_pay.setTextColor(getResources().getColor(R.color.mainRed));
			tv_all.setTextColor(Color.parseColor("#999999"));
			tv_by_send.setTextColor(Color.parseColor("#999999"));
			tv_by_get.setTextColor(Color.parseColor("#999999"));
			tv_by_comment.setTextColor(Color.parseColor("#999999"));

			v_line_all.setVisibility(View.INVISIBLE);
			line_by_pay.setVisibility(View.VISIBLE);
			line_by_send.setVisibility(View.INVISIBLE);
			line_by_get.setVisibility(View.INVISIBLE);
			line_by_comment.setVisibility(View.INVISIBLE);

			Collections.shuffle(mProduct);
			mAdapter.setNewData(mProduct);
		} else if (v == ll_by_send) {

			tv_by_send.setTextColor(getResources().getColor(R.color.mainRed));
			tv_all.setTextColor(Color.parseColor("#999999"));
			tv_by_pay.setTextColor(Color.parseColor("#999999"));
			tv_by_get.setTextColor(Color.parseColor("#999999"));
			tv_by_comment.setTextColor(Color.parseColor("#999999"));

			v_line_all.setVisibility(View.INVISIBLE);
			line_by_send.setVisibility(View.VISIBLE);
			line_by_pay.setVisibility(View.INVISIBLE);
			line_by_get.setVisibility(View.INVISIBLE);
			line_by_comment.setVisibility(View.INVISIBLE);

			mAdapter.setNewData(new ArrayList());
		} else if (v == ll_by_get) {

			tv_by_get.setTextColor(getResources().getColor(R.color.mainRed));
			tv_all.setTextColor(Color.parseColor("#999999"));
			tv_by_send.setTextColor(Color.parseColor("#999999"));
			tv_by_pay.setTextColor(Color.parseColor("#999999"));
			tv_by_comment.setTextColor(Color.parseColor("#999999"));

			v_line_all.setVisibility(View.INVISIBLE);
			line_by_get.setVisibility(View.VISIBLE);
			line_by_send.setVisibility(View.INVISIBLE);
			line_by_pay.setVisibility(View.INVISIBLE);
			line_by_comment.setVisibility(View.INVISIBLE);
			mAdapter.setNewData(new ArrayList());
		} else if (v == ll_by_comment) {

			tv_by_comment.setTextColor(getResources().getColor(R.color.mainRed));
			tv_all.setTextColor(Color.parseColor("#999999"));
			tv_by_send.setTextColor(Color.parseColor("#999999"));
			tv_by_get.setTextColor(Color.parseColor("#999999"));
			tv_by_pay.setTextColor(Color.parseColor("#999999"));

			v_line_all.setVisibility(View.INVISIBLE);
			line_by_comment.setVisibility(View.VISIBLE);
			line_by_send.setVisibility(View.INVISIBLE);
			line_by_get.setVisibility(View.INVISIBLE);
			line_by_pay.setVisibility(View.INVISIBLE);
			mAdapter.setNewData(new ArrayList());

		}
	}
}
